define([
  ELMP.resource('plugins/transform3/lib/babel_standalone_6.26.0_babel.min.js', 'lib'),
  ELMP.resource('plugins/transform3/lib/vue2-sfc-loader.min.js', 'lib'),
  ELMP.resource('plugins/transform3/lib/less.min.js', 'lib'),
  'vue',
  'vuex'
], function (Babel, vue3SfcLoader,less,Vue,vuex) {
  const options = {
    moduleCache: {
      vuex,
      vue: Vue,
      less: {
        render(source,options,callback){
          less.render(source,callback)
          return {
            code: '',
            errors:[]
          }
        }
      }
    },
    async getFile(url) {
      if(url.includes('@')){
        const reg = /\@\/(.+?)\/(.+)/.exec(url)
        url = ELMP.resource(reg[2],reg[1])
      }
      const res = await fetch(url);
      if (!res.ok)
        throw Object.assign(new Error(res.statusText + ' ' + url), { res });
      return {
        getContentData: async asBinary => {
          return asBinary ? res.arrayBuffer() : res.text()
        },
      }
    },
    addStyle(textContent) {
      const style = Object.assign(document.createElement('style'), { textContent });
      const ref = document.head.getElementsByTagName('style')[0] || null;
      document.head.insertBefore(style, ref);
    },
  }

  const { loadModule } = vue3SfcLoader;
  return {
    load: function (name, req, onload, config) {
      if(name.includes('@')){
        const reg = /\@\/(.+?)\/(.+)/.exec(name)
        name = ELMP.resource(reg[2],reg[1])
      }
      loadModule(req.toUrl(name).replace(/\?.+/, ''), options).then(onload)
    },
  };
});
